package edu.uj.petri.controller;

import edu.uj.petri.commands.AddRemoveTokensCommand;
import edu.uj.petri.commands.Command;
import edu.uj.petri.document.Document;
import edu.uj.petri.model.Place;
import edu.uj.petri.view.Canvas;
import edu.uj.petri.view.DiagramElement;
import edu.uj.petri.view.PlaceView;
import java.awt.geom.Point2D;

public class AddTokensEventHandler implements EventHandler {

    public AddTokensEventHandler()
    {
        Document.getActiveDocument().getView().selectNone();
                if (NewInhibitorArcEventHandler.unfinished != null) 
        {
            Document.getActiveDocument().getView().removeElement(NewInhibitorArcEventHandler.unfinished);
            Document.getActiveDocument().getView().draw();
            NewInhibitorArcEventHandler.unfinished = null;
            
        } else if (NewNormalArcEventHandler.unfinished != null)  
        {
            Document.getActiveDocument().getView().removeElement(NewNormalArcEventHandler.unfinished);
            Document.getActiveDocument().getView().draw();
            NewNormalArcEventHandler.unfinished = null;
        }
    }
    
    public void click(double x, double y) {
        
        DiagramElement e = Document.getActiveDocument().getView().getClickedElement( new Point2D.Double( x, y ), true);
        if (e instanceof PlaceView)
        {
            Command c = new AddRemoveTokensCommand( (Place)(((PlaceView)e).getNode()), 1);
            Document.getActiveDocument().execute(c);   
        }
    }

    public void doubleClick(double x, double y) {
    }

    public void mouseMove(double x1, double y1, int button) {
    }

    public void mouseButtonDown(double x, double y) {
    }

    public void mouseButtonUp(double x, double y) {
    }

    public void rightClick(double x, double y) {
    }

    /**
     * handles Escape and Delete
     */
    public void keyPressed(int keyCode) {
    }

    public void mouseDragged(double x, double y) {
    }

}
